// pages/Toplist/Toplist.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id:'',
        name:'',
        playlist:{},
        songlist:[],
    },
    // 获取歌单详情
    async getToplist(){
        const res = await wx.p.request({
            url:`${wx.root}/playlist/detail`,
            data:{
                id:this.data.id
            },
            time:''
        })
        res.data.playlist.shareCount = this.changeNum(res.data.playlist.shareCount)
        res.data.playlist.commentCount = this.changeNum(res.data.playlist.commentCount)
        res.data.playlist.subscribedCount = this.changeNum(res.data.playlist.subscribedCount)
        this.setData({
            playlist:res.data.playlist,
            songlist:res.data.privileges
        })
    },
    changeNum(num){
        if(num >= 100000000) 
            return parseInt(num/100000000)+'.'+parseInt(num%100000000/10000000)+'亿'
        else if(num >= 10000)
            return parseInt(num/10000)+'.'+parseInt(num%10000/1000)+'万'
        else  return num+''
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            id:options.id,
            name:options.name,
            time:options.time
        })
        wx.setNavigationBarTitle({
          title: options.name,
        })
        this.getToplist()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})